﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using MCDomain.DataAccess;
using MCDomain.Model;
using McReports;
using McReports.Common;
using McReports.ViewModel;
using McUIBase.Factories;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace McReportsTests
{
    class TestTemplateProvider:ITemplateProvider
    {
        public TestTemplateProvider(string templatePath)
        {
            TemplatePath = templatePath;
        }

        public string GetTemplate(string propertyName)
        {
            return TemplatePath;
        }

        public string TemplatePath { get; private set; }
    }

    [TestClass]
    public class McReportTests
    {
        private void CreateReport(BaseReportViewModel reportViewModel, string fileName)
        {
            reportViewModel.TemplateProvider = new TestTemplateProvider(fileName);
            var factory = new ReportFactoryBase();
          //  factory.CreateReport(reportViewModel);
        }

       
        [TestMethod]
     public void TransferAct9Test()
        {
            ContextFactoryService.Instance.QueryLoginProvider = new StubQueryLoginProvider();
            var rpt = RepositoryFactory.CreateEmptyRepository();
            var report = new ActTransferReport9ViewModel(rpt);
            var ctx = rpt.TryGetContext();
            var act = new Transferact() {Num = 10000, Id = 9999, Signdate = DateTime.Today, };
            
            rpt.Transferacts.Add(act);

            var contract1 = new Contractdoc() { Internalnum = "200-09-1", Approvedat = DateTime.Today };
            // поля Internalnum и Approvedat не заполнены
            var contract2 = new Contractdoc() { Price = 10 }; 
            var contractor = new Contractor() {Name = "ООО \"Газпромдобыча Ямбург\""};
            // не задано значение поля Name
            var contractor2 = new Contractor(); 

            var doc1 = new Document() { Name = "Договор" };
            var doc2 = new Document() { Name = "Задание" };
            var doc3 = new Document() { Name = "Календарный план" };
            var doc4 = new Document() { Name = "Протокол" };
            var doc5 = new Document() { Name = "Письма" };
            var doc6 = new Document() { Name = "Протокол1" };

            contract1.Contractorcontractdocs.Add(new Contractorcontractdoc(){Contractor = contractor});
            act.Contracttranactdocs.Add(new Contracttranactdoc(){Contractdoc = contract1, Document = doc1, Pagescount = 5});
            act.Contracttranactdocs.Add(new Contracttranactdoc() { Contractdoc = contract1, Document = doc1, Pagescount = 5 });
            act.Contracttranactdocs.Add(new Contracttranactdoc() { Contractdoc = contract1, Document = doc2, Pagescount = 1 });
            act.Contracttranactdocs.Add(new Contracttranactdoc() { Contractdoc = contract1, Document = doc3, Pagescount = 2 });
            act.Contracttranactdocs.Add(new Contracttranactdoc() { Contractdoc = contract1, Document = doc4, Pagescount = 3 });
            act.Contracttranactdocs.Add(new Contracttranactdoc() { Contractdoc = contract1, Document = doc5}); 
            act.Contracttranactdocs.Add(new Contracttranactdoc() { Contractdoc = contract1, Document = doc6});

            contract2.Contractorcontractdocs.Add(new Contractorcontractdoc(){Contractor = contractor2});
            act.Contracttranactdocs.Add(new Contracttranactdoc() { Contractdoc = contract2, Document = doc1, Pagescount = 5 });
            act.Contracttranactdocs.Add(new Contracttranactdoc() { Contractdoc = contract2, Document = doc1, Pagescount = 2 });
            act.Contracttranactdocs.Add(new Contracttranactdoc() { Contractdoc = contract2, Document = doc2 });
            act.Contracttranactdocs.Add(new Contracttranactdoc() { Contractdoc = contract2, Document = doc3, Pagescount = 1 });
            act.Contracttranactdocs.Add(new Contracttranactdoc() { Contractdoc = contract2, Document = doc4, Pagescount = 1 });
            act.Contracttranactdocs.Add(new Contracttranactdoc() { Contractdoc = contract2, Document = doc5, Pagescount = 4 });
            act.Contracttranactdocs.Add(new Contracttranactdoc() { Contractdoc = contract2, Document = doc6, Pagescount = 8 });

                report.TransferActId = 9999;
            CreateReport(report, @"C:\Projects\Irino\MContracts\Templates\9_act.dot");
            report.SetReport(); 
        }

           [TestMethod]
        public void InformConcludedContract()
        {
            ContextFactoryService.Instance.QueryLoginProvider = new StubQueryLoginProvider();
            var rpt = RepositoryFactory.CreateContractRepository();
            //var rpt = RepositoryFactory.CreateEmptyRepository();
            var report = new InformationConcludedContracts_ViewModel(rpt);
           
            CreateReport(report, @"C:\Projects\Irino\MContracts\Templates\InformationConcludedContracts.xlt");

            var date1 = new DateTime(2011, 10, 1, 0, 0, 0); //год месяц день 
            var date2 = new DateTime(2011, 12, 30, 0, 0, 0);
            report.StartData = date1;
            report.EndData = date2;
            report.SetReport();
        }
    }
}
